package main

import (
	"fmt"
	"math/rand"
	"strconv"
	"time"
)

var DeviceKeys = []string{"dianbiao01", "dianbiao02", "dianbiao03", "dianbiao04", "dianbiao05"}
var ModelKeys = []string{"d01", "d02", "d03", "d04", "d05"}

// demo11 协程 开发 练习
func demo11Lianxi() {
	now := time.Now().Unix()
	t := time.Unix(now-3600*24*365, 0)
	fmt.Println(strconv.ParseInt(t.Format("2006010215"), 10, 64))
	var v = make(chan float64, 2)
	v <- 1.0 // 写入值
	// 需求如下： 年月日 ymd  时间戳  值
	go func() {
		fmt.Println(<-v)
		l := GetData(now-3600*24*30, 3600, now, &v)
		fmt.Println(l)
		fmt.Println(<-v)
	}()

	time.Sleep(time.Second * 2)
}

// 获取到数据
func GetData(startT int64, muT int64, endT int64, v *chan float64) (total int64) {
	fmt.Printf("时间段：%s ~ %s \n", time.Unix(startT, 0).Format("2006-01-02 15:04:05"), time.Unix(endT, 0).Format("2006-01-02 15:04:05"))
	for startT < endT {
		//now := time.Unix(startT, 0)
		fmt.Println("时间戳：", startT)
		//fmt.Printf("时间戳：%d, 值：%s\n", startT, now.Format("2006-01-02 15:04:05"))
		startT += muT
		total++
		v1 := <-*v
		fmt.Println(v1)
		v1 += rand.Float64()
		*v <- v1
		//*v <- v1
		// v = <-v
		// *v += rand.Float64()
	}
	fmt.Printf("总条数：%d \n", total)
	return
}
